<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Stop extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	function __construct()
	{
		parent::__construct();
		$this->load->model('ktig');
	}
	public function index()
	{
		$this->load->helper('url');
		$this->load->view('header');
		
		$this->ktig->is_logged_in();
		$this->load->view('v_stop');
		
		
	}
	public function instruksi()
	{
		$this->load->helper('url');
		$this->load->view('header');
		
		$this->ktig->is_logged_in();
		$this->load->view('v_stop_instruksi');
		
		
	}
	public function lihat()
	{
		$this->load->helper('url');
		$this->load->view('header');
		
		$data['datalist'] = $this->ktig->list_kartu_stop();
		
		$this->ktig->is_logged_in();
		/*if($this->session->userdata('role')==5 or $this->session->userdata('role')==4 or $this->session->userdata('role')==1)
		{*/
		$this->load->view('v_stop_lihat',$data);
		/*}
		else { redirect('land'); }*/
	}
	public function input_form()
	{
		$this->load->helper('url');
		/*
		$tanggal_input = $this->input->post('waktu');
		$tanggal = date("Y-m-d", strtotime($tanggal_input));
		$jam = date("H:i:s", strtotime($tanggal_input));
		*/
		
		$tanggal_input = $this->input->post('tanggal');
		$jam_input = $this->input->post('jam');
		$tanggal = date("Y-m-d", strtotime($tanggal_input));
		$jam = date("H:i:s", strtotime($jam_input));
		
		//if($this->input->post('aman')=="kondisi") { $aman=1; } else { $aman=null; }
		//if($this->input->post('aman2')=="kondisi") { $aman2=1; } else { $aman2=null; }
		
		$data=array(
			'TANGGAL'=>$tanggal,
			'JAM'=>$jam,
			'LOKASI'=>$this->input->post('lokasi'),
			'DEPARTEMEN'=>$this->input->post('departemen'),
			'KONDISI_TINDAKAN'=>$this->input->post('aman'),
			'STATUS_REKOMENDASI'=>$this->input->post('aman2'),
			'DESKRIPSI'=>$this->input->post('desc'),
			'REKOMENDASI'=>$this->input->post('rec'),
			'NAMA_PEMEGANG'=>$this->input->post('nama'),
			'NAMA_PELANGGAR'=>$this->input->post('nama1')
		  );
		$this->db->insert('kartu_stop',$data);
		
		redirect('stop/lihat');
	}
	public function ubah($id)
	{
		$this->load->helper('url');
		$this->load->view('header');
		if($this->input->post('submit'))
		{
			$this->ktig->update_stop($id);
			redirect('stop/lihat');
		}
		
		$this->ktig->is_logged_in();
		if($this->session->userdata('role')==5 or $this->session->userdata('role')==4 or $this->session->userdata('role')==1)
		{
			$data['hasil']=$this->ktig->data_stop($id);
			$this->load->view('v_stop_ubah',$data);
		}
		else { redirect('land'); }
	}
	public function hapus($id)
	{
		$this->load->helper('url');
		$this->ktig->hapus_stop($id);
		
		$this->ktig->is_logged_in();
		if($this->session->userdata('role')==5 or $this->session->userdata('role')==1)
		{
			redirect('stop/lihat');
		}
		else { redirect('land'); }
	}
	public function detail($id)
	{
		$this->load->helper('url');
		$this->load->view('header');
		if($this->input->post('submit'))
		{
			redirect('stop/lihat');
		}
		
		$this->ktig->is_logged_in();
		//if($this->session->userdata('role')==5 or $this->session->userdata('role')==4 or $this->session->userdata('role')==1 or $this->session->userdata('role')==3)
		//{
		$data['hasil']=$this->ktig->data_stop($id);
		$this->load->view('v_stop_detail',$data);
		//}
	//	else { redirect('land'); }
		
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */